package cn.niit.dao;

import cn.niit.entity.SysRole;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SysRoleMapper {
    @Insert({
        "insert into tb_sys_role (id, role_name, ",
        "role_remarks, role_level, ",
        "del_flag, status, gmt_create, ",
        "gmt_update, create_user_id, ",
        "create_user_name, modify_user_id, ",
        "modify_user_name, role_permissions)",
        "values (#{id,jdbcType=BIGINT}, #{roleName,jdbcType=VARCHAR}, ",
        "#{roleRemarks,jdbcType=VARCHAR}, #{roleLevel,jdbcType=TINYINT}, ",
        "#{delFlag,jdbcType=BIT}, #{status,jdbcType=BIT}, #{gmtCreate,jdbcType=TIMESTAMP}, ",
        "#{gmtUpdate,jdbcType=TIMESTAMP}, #{createUserId,jdbcType=BIGINT}, ",
        "#{createUserName,jdbcType=VARCHAR}, #{modifyUserId,jdbcType=BIGINT}, ",
        "#{modifyUserName,jdbcType=VARCHAR}, #{rolePermissions,jdbcType=VARCHAR})"
    })
    int insert(SysRole record);

    int insertSelective(SysRole record);

//    @Select("select id, role_name as roleName from t_sys_role order by id")
//    List<RoleSelectResponseVO> getAllWithSelect();

    /**
     * 根据用户ID查询该用户所有角色标识
     * @param userId
     * @return
     */
    @Select("SELECT t2.role_permissions " +
            "FROM `tb_sys_user_role` t1,`tb_sys_role` t2 " +
            "WHERE t1.`user_id`=#{userId} AND t1.`role_id`=t2.`id` " +
            "AND t2.STATUS=1 AND t2.del_flag=0 " +
            "AND t2.role_permissions<> ''")
    List<String> listUserRoles(@Param("userId") Long userId);
}